package org.richin.collection.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

import org.apache.commons.collections.iterators.ArrayListIterator;

public class ArraysList<E> extends ArrayList<E> {
	private transient Object[] elementData;

	/**
	 * The size of the ArrayList (the number of elements it contains).
	 * 
	 * @serial
	 */
	private int size;

	public ArraysList(int initialCapacity) {
		super();
		if (initialCapacity < 0)
			throw new IllegalArgumentException("Illegal Capacity: "
					+ initialCapacity);
		this.elementData = new Object[initialCapacity];
	}
    public ArraysList() {
    	this(10);
        }
    public ArraysList(Collection<? extends E> c) {
    	elementData = c.toArray();
    	size = elementData.length;
    	// c.toArray might (incorrectly) not return Object[] (see 6260652)
    	if (elementData.getClass() != Object[].class)
    	    elementData = Arrays.copyOf(elementData, size, Object[].class);
        }
	/**
	 * 
	 */
	private static final long serialVersionUID = -5177168942199544431L;

	@Override
	public void add(int index, E element) {
		if (index > size || index < 0)
			throw new IndexOutOfBoundsException("Index: " + index + ", Size: "
					+ size);

		ensureCapacity(size + 1); // Increments modCount!!
		System.arraycopy(elementData, index, elementData, index + 1, size
				- index);
		elementData[index] = element;
		size++;
	}
	public static void main(String[] args) {
		ArraysList list =new ArraysList();
		list.add(3);
	}
}
